package com.jzo2o.customer.service.impl;

import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.common.utils.ObjectUtils;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.mvc.utils.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 银行账户 服务实现类
 * </p>
 *
 * @author Echo
 * @since 2025-03-07
 */
@Service
@RequiredArgsConstructor
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {

    /**
     * 添加银行账户
     * @param dto
     */
    @Override
    public void saveAccount(BankAccountUpsertReqDTO dto) {
        Long userId = UserContext.currentUserId();
        BankAccount bankAccount = BeanUtils.copyBean(dto, BankAccount.class);
        bankAccount.setId(userId);
        bankAccount.setType(dto.getType());
        save(bankAccount);
    }

    /**
     * 根据服务人员id查询银行账户信息
     * @return
     */
    @Override
    public BankAccountResDTO queryByServeProviderId() {
        Long userId = UserContext.currentUserId();
        BankAccount account = lambdaQuery().eq(BankAccount::getId, userId).one();
        if (ObjectUtils.isNotEmpty(account)) {
            return BeanUtils.copyBean(account, BankAccountResDTO.class);
        }
        return null;
    }
}
